package com.lm.scau.dyb.view;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lm.scau.dyb.R;
import com.lm.scau.dyb.activity.base.BaseActivity;

/**
 * Function:
 * auth：liming on 2016/8/5 14:16
 * mail：liming@wxchina.com
 */
public class LoadingDialog extends Dialog {
    private BaseActivity context;
    private TextView tipTextView;
    private View view;

    public LoadingDialog(Context context) {
        super(context);
        this.context = (BaseActivity) context;
        initView();
    }

    private void initView() {
        LayoutInflater inflater = LayoutInflater.from(context);
        view = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
       // LinearLayout layout = (LinearLayout) view.findViewById(R.id.dialog_view);// 加载布局
        tipTextView = (TextView) view.findViewById(R.id.tipTextView);// 提示文字
        setTipText("请稍后...");// 设置加载信息
        this.setCancelable(false);// 不可以用“返回键”取消
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.setContentView(view, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局
    }

    /**
     * 设置显示文字
     *
     * @param tip
     */
    public void setTipText(String tip) {
        tipTextView.setText(tip);
    }

    @Override
    public void show() {
        // main.xml中的ImageView
        ImageView spaceshipImage = (ImageView) view.findViewById(R.id.img);
        // 加载动画
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
                context, R.anim.loading_animation);
        // 使用ImageView显示动画
        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
        super.show();
    }
}
